package com.jk.tweetsnear.list.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jk.tweetsnear.MainActivity;
import com.jk.tweetsnear.R;

public class TweetListBaseAdapter extends BaseAdapter
{

	private Context context;
	public ImageLoader imageLoader; 

	public TweetListBaseAdapter(Context context, int textViewResourceId)
	{
		super();
		this.context = context;
		imageLoader=new ImageLoader(context.getApplicationContext());
	}

	@Override
	public int getCount()
	{
		return MainActivity.arrayTweetData.size(); 
	}

	@Override
	public Object getItem(int position)
	{
		String result = new String(position + "");
		return result;
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		View v = convertView;
		if (v == null)
		{
			LayoutInflater vi = LayoutInflater.from(context);
			v = vi.inflate(R.layout.row_tweet_list_listview, null);
		}

		String value = (String) this.getItem(position);
		if (value != null)
		{

			int size = MainActivity.arrayTweetData.size();
			if(size > 0)
			{
				TextView textView1 = (TextView) v.findViewById(R.id.txt_row_list_name);
				textView1.setText(MainActivity.arrayTweetData.get(position).getName());
	
				TextView textView2 = (TextView) v.findViewById(R.id.txt_row_list_screenName);
				textView2.setText("@" + MainActivity.arrayTweetData.get(position).getScreenName());
				
				TextView textView3 = (TextView) v.findViewById(R.id.txt_row_list_contents);
				textView3.setText(MainActivity.arrayTweetData.get(position).getText());		
				
				TextView textView4 = (TextView) v.findViewById(R.id.txt_row_list_createAt);
				textView4.setText(MainActivity.arrayTweetData.get(position).getCreateTime());						
				
				ImageView ivProfile = (ImageView) v.findViewById(R.id.iv_row_list_profile);
				imageLoader.DisplayImage(MainActivity.arrayTweetData.get(position).getProfileUrl(), ivProfile);
			}
		}
		return v;
	}

}